/**
 * @file RemoveLayerCommand.cpp
 *
 * @date 30/12/2011
 * @author Tales 
 *
 */

#include "RemoveLayerCommand.hpp"
#include "PictureState.hpp"

namespace yep
{

RemoveLayerCommand::RemoveLayerCommand(int pos, size_t qtd) :
		Command(Color::BLACK, pos)
{
	position = pos;
	quantity = qtd;
}

void RemoveLayerCommand::execute(PictureState & state)
{
	if (position >= 0)
	{
		int endPos = position + quantity;
		int delta = state.getLayerCount() - endPos;
		for (size_t i = 0; i < quantity; ++i)
		{
			const int basePos = position + (quantity - i - 1);
			for (int j = 0; j < delta; ++j)
			{
				state.swap(basePos + j, basePos + j + 1);
			}
		}
	}
	state.removeLayer(quantity);
}

} /* namespace yep */
